// pages/roleSelection/roleSelection.js
Page({
  data: {
    selectedRole: null
  },
  
  selectRole: function(e) {
    const role = e.currentTarget.dataset.role;
    this.setData({
      selectedRole: role
    });
    
    // 添加动画效果
    this.animate(`.role-card[data-role="${role}"]`, [
      { scale: 1, opacity: 1 },
      { scale: 0.95, opacity: 0.6 },
      { scale: 1, opacity: 1 }
    ], 500, () => {
      this.clearAnimation(`.role-card[data-role="${role}"]`);
    });
  },
  
  confirmSelection: function() {
    if (!this.data.selectedRole) return;
    
    // 显示加载状态
    wx.showLoading({
      title: '正在确认',
    });
    
    // 模拟网络请求
    setTimeout(() => {
      wx.hideLoading();
      
      // 根据选择跳转到不同页面
      switch(this.data.selectedRole) {
        case 'park':
          wx.redirectTo({ url: '/pages/park/home' });
          break;
        case 'enterprise':
          wx.redirectTo({ url: '/pages/enterprise/home' });
          break;
        case 'accountant':
          wx.redirectTo({ url: '/pages/accountant/home' });
          break;
        case 'agency':
          wx.redirectTo({ url: '/pages/agency/home' });
          break;
      }
      
      // 可以在这里存储用户选择的角色到全局或本地
      getApp().globalData.userRole = this.data.selectedRole;
    }, 800);
  }
});